﻿using Native.Sdk.Cqp.EventArgs;
using System.IO;
using System.Text;
using github.heerheer.card2.Code.Helper;
using Native.Sdk.Cqp;
using PCRRPG.Code.EconomySystem;

namespace Code
{
    public class Event_Bag : IMessageEvent
    {
        public string Message => AppMain.commandHelper.BagCommand;

        public void Process(CQPrivateMessageEventArgs e)
        {
            //throw new NotImplementedException();
        }

        public void Process(CQGroupMessageEventArgs e)
        {
            var path = $"{e.CQApi.AppDirectory}saves\\{e.FromGroup.Id.ToString()}\\{e.FromQQ.Id.ToString()}.json";
            if (File.Exists(path))
            {
                //var playerdata = File.Exists(path) ? LitJson.JsonMapper.ToObject<HeerCards.Info.HCPlayer>(File.ReadAllText(path)) : new HeerCards.Info.HCPlayer();
                StringBuilder sb = new StringBuilder();
                //sb.AppendLine(e.FromQQ.CQCode_At().ToString()+"您的信息已生成");
                sb.AppendLine(CQApi.CQCode_Emoji(128180).ToString() + "您的货币信息：");
                foreach (var item in EconomyOperater.getAllMoney(e.FromQQ.Id, e.FromGroup.Id)) { 
                     sb.AppendLine($"{item.Key} {item.Value}");
                } 
                //sb.AppendLine(CQApi.CQCode_Emoji(127873).ToString() + "您的背包信息：");
                //foreach (var item in playerdata.Cards)
                //{
                //    sb.AppendLine(item.Name + "*" + item.Count);
                //}
                e.FromGroup.SendGroupMessage(sb.ToString().TrimEnd('\n'));
            }
            else
            {
                e.FromGroup.SendGroupMessage(AppMain.commandHelper.getCommand("Reply.Bag.Error"));
            }
        }
    }
}